import request from './request'

// 通用接口类型定义
export interface DictItem {
  label: string
  value: string | number
  disabled?: boolean
}

export interface FileUploadResult {
  url: string
  filename: string
  size: number
  type: string
}

// 通用API
export const commonApi = {
  // 获取银行列表
  getBankList(): Promise<DictItem[]> {
    return request.get('/common/banks')
  },

  // 获取文件类型列表
  getFileTypeList(): Promise<DictItem[]> {
    return request.get('/common/file-types')
  },

  // 获取标准字段列表
  getStandardFields(): Promise<Array<{
    name: string
    description: string
    type: string
  }>> {
    return request.get('/common/standard-fields')
  },

  // 文件上传
  uploadFile(file: File, type?: string): Promise<FileUploadResult> {
    const formData = new FormData()
    formData.append('file', file)
    if (type) {
      formData.append('type', type)
    }
    return request.upload('/common/upload', formData)
  },

  // 获取系统配置
  getSystemConfig(): Promise<Record<string, any>> {
    return request.get('/common/config')
  },

  // 健康检查
  healthCheck(): Promise<{ status: string; timestamp: number }> {
    return request.get('/common/health')
  }
}